function callStringCommand ()
{
    # �����ַ�����ʽ������
    # ʹ�� &
    # �������Ĳ���:  http://edgylogic.com/blog/powershell-and-external-commands-done-right/
    $command = "ls";
    & $command;
}

function call_cmd_command ($command)
{
    $cmd = "cmd.exe";
    $command = "/c "+ $command ;
    & $cmd $command;
}

function call_CMD_command ()
{
    $cmd = "cmd.exe";
    $argsX = "/c sqlplus user/password@server/sid @C:\temp\SQL\alex.sql";
    &$cmd $argsX;
}

function getAllAssembliesLoaded()
{
    [System.AppDomain]::CurrentDomain.GetAssemblies() | 
            Where-Object Location | 
            Sort-Object -Property FullName | 
            Select-Object -Property Name, Location, Version | 
            Out-GridView;
}

function getTotalValOfArray ()
{
    $a = 1..34  #���� 1 �� 34 ������
    $sum = $a -join '+'  
    #�����ַ�������
    Invoke-Expression $sum 
}

function joinArray ()
{
     $a = 1..34 
    $sum = $a -join '+'  
    $sum
}

function joinArray_NewLine ()
{
     $a = 1..34 
    $sum = $a -join "`r`n"
    $sum
    #$sum| Out-String
}

function newLine ()
{
    $body = "This`nIs`nA`nTest"  
    $body 
}
<#
#ת���ַ�
function escapeCharacter ()
{
    $str =  ("{{0}}" -F 2);
    Write-Host $str ;  #���: {0}
    $str =  ("{{{0}}}" -F 2) ;
    Write-Host $str ;   #���: {2}  //�ڸ�ʽ����ת���� { ��  }
    $str =  ("`{{0}`}" -F 2) ;
    Write-host  $str ;  #���: {0}

    $str = "`""; # ʹ�� ` ������ת��
    Write-host  ($str -eq """") ;
}
#>

function removeRepeatLineInFile ()
{
    #�õ�.net�еķ�����HashSet
    #HashSet<T>����Ҫ����������������ܼ�����ģ���������������󽻼�����������ȡ�

    $spath="c:\Users\softy\Desktop\EAO.TXT"
    $dpath="c:\Users\softy\Desktop\EAO_NEW.TXT"
 
    [System.Collections.Generic.HashSet[string]]$lines=Get-Content -Path $spath -ReadCount 0
   Set-Content  -Path $dpath -Value ($lines -join "`r`n")

    #���ƹ��� ;;���������ʧ����......�����Ǹ��ɹ���.....ϯ��
    $ls=Get-Content -Path $spath -ReadCount 0|Select-Object -Unique
    Set-Content -Path $dpath -Value ($lines -join "`r`n")
}

function addElementIntoArray ()
{
     $array = @();
     $array +=1;
     $array +=2;
     Write-Host $array;

     # add Array to another Array
    $a = @(1,2,3);
    $b = @(1,2,3);
    $a +=$b;
    $a
}

function getDesktopPath()
{
    $DesktopPath = [System.Environment]::GetFolderPath([System.Environment+SpecialFolder]::Desktop);
    return $DesktopPath;
}

function callOtherFunctionInAnotherScript()
{
    # !!! ע��: ������ں���������ű�,��ô�ű��еĺ�����ֻ���ڸú�������Ч,���˸ú�����ʧЧ !!!
    # ע����ǰ����Ǹ� .
    # $PSScriptRoot��Powershell2.0+ʱ�����,ָ����ǰ�ű���ִ��·��
    . $PSScriptRoot\tip_1.ps1 ;
    callStringCommand;
}

function getCurrentScriptLocation ()
{
    # powershell3.0+
     $PSScriptRoot

     # powershell2.0
     Split-Path -Parent $MyInvocation.MyCommand.Path
     #. ([System.IO.Path]::Combine((Split-Path $MyInvocation.MyCommand.Path),"output.ps1"));    
     #$MyInvocation.MyCommand.Name
}

function  variableInString()
{
    #http://www.pstips.net/expanding-variables-in-strings.html
}

function hasSpecialProperty ($obj, $propertyName)
{
    #powerShell v3   --- ʧ�ܣ�����
     # return [bool]($obj.PSobject.Properties.name -match $propertyName); 
     #powerShell v2
    return [bool](Get-Member -inputobject $obj -name $propertyName -Membertype Properties)
}

function isArray ($obj)
{
   # -isnot
    return ($obj -is [system.array]);
}

function  getDefine($param1, $param2)
{
    "" | gm substring | select definition  # ��ȡ�ַ�����substring�����Ķ���
}

function deleteLastChar ($str)
{
  # ʹ������
   return  $str   -replace ��.$��;
}
<#  ͳ��ָ��Ŀ¼��,ָ�������ļ������� #>
function getCount4SpecialTypeFile ($type,$dirPath)
{
    $type = $type.ToLowerInvariant();
    Get-ChildItem $dirPath -Force -Recurse | 
                                                                                 ?{$_.PSIsContainer -eq $false}| 
                                                                                 ?{$_.Name.ToLowerInvariant().EndsWith("."+$type)} |
                                                                                 Measure-Object |
                                                                                  Select-Object -ExpandProperty Count
}

function addContentToCurrentFile ()
{
    Add-content $file.pspath -Value $liner #�������ݵ�ԭ�ļ�
}

function loadDotNetAssembly ()
{
        <#
    # PowerShell v2.0 +
    # You can define new types in PowerShell v2.0 using the Add-Type cmdlet:
    # �Զ�����.NET���
    #>
    #�μ�oneNote�е�Temp�µ�OOP in Powershell
    # �Ѿ�ͬ����µ�Ŀ¼oop

    #����.NET���
    Add-Type -AssemblyName mscorlib
    $str = New-Object System.Text.StringBuilder
    $str.Append("Hello")
}

function clearFileContent ($file)
{
    clear-content $file.pspath  #���ÿ���ļ�����

    #clearFileContent (Get-Content d:\1.txt)
}

function compareObj ($param1, $param2)
{
     <#
        Compare-Object �� Alias
    #>

    # û���������,ֻ����˱ȽϵĽ��
    $c = compare  -ReferenceObject (1..5) -DifferenceObject (1..6) -PassThru
    $c 

    $a1=@(1,2,3,4,5)
    $b1=@(1,2,3,4,5,6)
    (Compare-Object $a1 $b1).InputObject
    (Compare-Object $b1 $a1).InputObject   
}

function getAlias ($param1, $param2)
{
     # ��ѯ������ָ����ʵcmdlet���� ��
    Get-Alias -name ls   
}

function getContent ($param1, $param2)
{
   $file = "F:\2014\7-22-new-2014-08-26.docx"

<#        Get-DocumentText        #>
<#
$wordApp = New-Object -COM Word.Application
$file = "F:\2014\7-22-new-2014-08-23.docx"#(dir F:\2014\7-22-new-2014-08-23).FullName
$doc = $wordApp.Documents.Open($file)
$text = $doc.Content.Text
$text
$wordApp.Exit
#>
<#  Get-DocumentParagraph   
$wordApp = New-Object -COM Word.Application
#$file = (dir Sample.doc).FullName
$doc = $wordApp.Documents.Open($file)
$paragraphs = $doc.Paragraphs
foreach ($paragraph in $Paragraphs)
{
Write-Host "PARAGRAPH:"
Write-Host $paragraph.Range.Text
}
$wordApp.Quit()
 #>

 <#  Get-DocumentSentences 
 $wordApp = New-Object -COM Word.Application
#$file = (dir Sample.doc).FullName
$doc = $wordApp.Documents.Open($file)
$sentences = $doc.Sentences
foreach ($sentence in $sentences)
{
Write-Host "Sentence:"
Write-Host $sentence.Text
}
$wordApp.Quit()

   #>


  <# ֻ����Doc�ĵ��ĸ�ʽ;����ȫ��ɾ��
$word = New-Object -comobject Word.Application 
$word.Visible = $True 
 
$doc = $word.Documents.Open("F:\2014\7-22-new-2014-09-11.docx") 
 
$sel = $word.Selection 
$paras = $doc.Paragraphs  #����
 
foreach ($para in $paras) 
{ 
    $style = $para.Style 
    If ($style.NameLocal -ne "Heading 1") 
    { 
        $para.Range.Select() 
        $sel.Cut() 
    } 
} 
$doc.SaveAs([ref] "F:\2014\Headings.doc") 
$word.Quit() 
#>
$rows = 2; $columns = 5

$word = New-Object -ComObject word.application

$word.visible = $true

$document = $word.documents.add()

$range = $document.Range()

 

$table = $document.Tables.add($range,$rows,$columns)

$table.cell(1,1).range.text = "code"

$table.cell(1,2).range.text = "wingdings"

$table.cell(1,3).range.text = "wingdings2"

$table.cell(1,4).range.text = "wingdings3"

$table.cell(1,5).range.text = "courier new"

$j=2

For($i = 33 ; $i -le 255; $i++)
{

 $table.rows.add() | out-null

 $Table.Cell($j,1).range.Text = $i

 $cellRange = $Table.Cell($j,2).range

 $cellRange.collapse()

 $cellRange.InsertSymbol($i,"WingDings")

 $cellrange = $table.cell($j,3).range

 $cellrange.collapse()

 $cellrange.insertSymbol($i,"wingdings2")

 $cellrange = $table.cell($j,4).range

 $cellrange.collapse()

 $cellrange.insertSymbol($i,"wingdings3")

 $cellrange = $table.cell($j,5).range

 $cellrange.collapse()

 $cellrange.insertSymbol($i,"Courier New")

 $j++

} 
}

function getDate ($param1, $param2)
{
    Get-Date
}

function get_Member_Of_Type ($param1, $param2)
{
    #gm  get member ��ȡ��Ա

    <#
    #�˽��������Щ����:
    #>
    #	1. Get-service | Select-Object -First 1 | Format-List *
    #	2. Get-service | Select-Object -First 1 | Get-Member -MemberType Property


    #��
    [String] | gm   

    #ʵ��
    [String]("hi") | gm 

    #���Ǿ�̬����
    [Math].GetMethods()

    #����
    [Microsoft.PowerShell.Commands.GroupInfo] | Get-Member -MemberType Property    
}

function newObject ($param1, $param2)
{
     New-Object -TypeName System.Version -ArgumentList "1.2.3.4"
    $str = New-Object -TypeName System.String -ArgumentList "'*'.5"
    $str
}

function selectObject ($param1, $param2)
{
    # ��ѡΨһ��Ԫ��
    (Get-Process | Select-Object -Unique ).Length   #85
    # �Ա���
    (Get-Process ).Length   #101

    #��ȡǰ����,��ӡ�����ǵ�����
    Get-Item *.jar | Select-Object -First 2 | %{$_.Name}    
}

function startProcess ($param1, $param2)
{
    startProcess xx
}

function testPath_checkIf_File_or_folder ($param1, $param2)
{
    #Doc : https://technet.microsoft.com/en-us/library/ff730955.aspx

    <#
    #Using Test-Path to Verify the Existence of an Object
    #>
    Test-Path C:\Scripts\Archive\*.ps1


    <#
    check the object is file or folder
    #>
    #�μ�fileRelativeLib.ps1

    Test-Path C:\Scripts\Archive\* -exclude *.gif, *.jpg
}

<#
  #  ����ļ��м����ؼ���
  # Sample :  findAllMatchLineInSpecialFileType D:\Projects\JYXT\WebRoot\page\htgl\js js kq.alert
#>
function findAllMatchLineInSpecialFileType ($dirPath, $fileType,$content)
{
    # ��ָ��Ŀ¼��,
    #�ݹ����ָ�����͵��ļ�,
    #���ҳ�����ָ��������
     cd $dirPath;
     $a = Select-String  -Path (Get-ChildItem ./ -Recurse | ?{$_.Name -like ("*.{0}" -F $fileType)}) -Pattern $content
    $a    #>> c:/1.txt   
}

function getChildItem ($param1, $param2)
{
    #��ȡָ��Ŀ¼�£�����ָ�����Ƶ��ļ����ļ��У��ݹ鵽��
    Get-ChildItem ./ -Recurse | ?{$_.Name -like "theme"} | %{Write-Host $_.FullName}
}

function alias ($param1, $param2)
{
    $pshome
	
	#�鿴������Remove��ͷ��cmdlet������ı��� :  
	dir alias: | where {$_.Definition.Startswith("Remove")} ; 

	#�鿴���б�����ָ��cmdlet�ı����ĸ��� : 
	ls alias: | Group-Object definition | sort -Descending Count  >> d:/1.txt

	#ls alias: | Group-Object definition | %{$_.GetType().FullName}	
}
#callStringCommand;
#getAllAssembliesLoaded;
#getTotalValOfArray;
#escapeCharacter
# call_CMD_command;
#joinArray_NewLine
#removeRepeatLineInFile;
#addElementIntoArray;
#getDesktopPath;
#callOtherFunctionInAnotherScript
#hasSpecialProperty ��123�� ��Length��
#hasSpecialProperty ��123�� ��Len��
#getCount4SpecialTypeFile txt1 D:\111
